<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #check_user="{record}">
        <div v-if="record.check_user != 0">
            {{ record.create_user.nickname }}
        </div>
        <div v-else></div>
      </template>
      <template #operationBeforeExtend="{ record }">
        <a-link @click="handleShenhe(record)" v-if="record.check_status != 1">审核</a-link>
      </template>
    </ma-crud>

    <!-- 审核 -->
    <a-modal :mask-closable="false"  title="审核" v-model:visible="shenheShow" :width="1080" @cancel="handleDetailCancel" :on-before-ok="handleOk">
      <div v-if="shenheShow">
        <div class="flex " style="margin-bottom: 2%;">
          <div style="width: 100px;">部门：</div>
          <a-input :style="{width:'320px'}" placeholder="" v-model="fromDate.dept.name" disabled allow-clear />
        </div>
        <div class="flex " style="margin-bottom: 2%;">
          <div style="width: 100px;">提现金额：</div>
          <a-input :style="{width:'320px'}" placeholder="" v-model="fromDate.money" disabled allow-clear />
        </div>
        <!-- <div class="flex " style="margin-bottom: 2%;">
          <div style="width: 100px;">凭证：</div>
          <div>
            <a-space>
              <a-image v-for="(item,index) in fromDate.files" :key="index" :src="item" width="100" height="100" />
            </a-space>
          </div>
        </div> -->
        <div class="flex " style="margin-bottom: 2%;">
          <div style="width: 100px;">审核状态：</div>
          <div>
            <a-radio-group v-model="fromDate.check_status" :options="checkStatusList" >
              
            </a-radio-group>
          </div>
        </div>
        <div class="flex " style="margin-bottom: 2%;">
          <div style="width: 100px;">审核备注：</div>
          <div class="flex_1">
            <a-textarea v-model="fromDate.remark" placeholder="请输入审核备注" allow-clear/>
          </div>
        </div>
      </div>
    </a-modal>

  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import financialMoneyApply from '@/api/financial/financialMoneyApply'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const fromDate = ref({})
const shenheShow = ref(false)
const checkStatusList = ref([
        // {
        //   label: "待审核",
        //   value: 0
        // },
        {
          label: "审核成功",
          value: 1
        },
        // {
        //   label: "驳回",
        //   value: 2
        // }
])

const handleShenhe = (row)=>{
  fromDate.value = JSON.parse(JSON.stringify(row))
  if(fromDate.value.files == ''){
    fromDate.value.files = []
  }else{
    fromDate.value.files = fromDate.value.files.split(',')
  }
  fromDate.value.remark = ''
  shenheShow.value = true
}

const handleOk = async ()=>{
  let obj = {
    dept_id:fromDate.value.dept_id,
    money:fromDate.value.money,
    check_status:fromDate.value.check_status,
    remark:fromDate.value.remark
  }
  let res = await financialMoneyApply.update(fromDate.value.id,obj)
  if(res.code == 200){
    Message.success('审核成功')
    crudRef.value.refresh()
    return true
  }else{
    Message.error(res.message)
    return false
  }
  
}

const options = reactive({
  id: 'flyos_financial_money_apply',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: financialMoneyApply.getList,
  recycleApi: financialMoneyApply.getRecycleList,
  add: {
    show: true,
    api: financialMoneyApply.save,
    auth: ['financial:moneyApply:save']
  },
  edit: {
    show: false,
    api: financialMoneyApply.update,
    auth: ['financial:moneyApply:update']
  },
  delete: {
    show: false,
    api: financialMoneyApply.deletes,
    auth: ['financial:moneyApply:delete'],
    realApi: financialMoneyApply.realDeletes,
    realAuth: ['financial:moneyApply:realDeletes']
  },
  recovery: {
    show: false,
    api: financialMoneyApply.recoverys,
    auth: ['financial:moneyApply:recovery']
  },
  import: {
    show: false,
    url: 'financial/moneyApply/import',
    templateUrl: 'financial/moneyApply/downloadTemplate',
    auth: ['financial:moneyApply:import']
  },
  export: {
    show: false,
    url: 'financial/moneyApply/export',
    auth: ['financial:moneyApply:export']
  },
  
  
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "部门",
    dataIndex: "dept_id",
    formType: "select",
    search: true,
    dict: {
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      remote: "system/dept/remote",
      // 指定组件接收的props
      props: { label: "name", value: "id" },
      // 开启分页
      openPage: false,
      // 远程请求配置项
      remoteOption: {
        // 按用户名排序
        sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
        // 设置查询的字段
        select: ["id", "name"],
        // 设置数据过滤
        filter: {
          type: ["=", 2],
          status: ['=',1]
        },
        // 关联模型
        relations: [],
      },
      translation:true,
    },
  },
  {
    title: "提现金额",
    dataIndex: "money",
    formType: "input",
  },
  // {
  //   title: "凭证",
  //   dataIndex: "files",
  //   formType: "upload",
  //   type: "image",
  //   multiple: true,
  //   onlyData: true,
  //   returnType: "url"
  // },
  {
    title: "审核状态",
    dataIndex: "check_status",
    formType: "select",
    search: true,
    addDisplay: false,
    dict: {
      data: [
        {
          label: "待审核",
          value: "0"
        },
        {
          label: "审核成功",
          value: "1"
        },
        {
          label: "驳回",
          value: "2"
        }
      ],
      translation: true
    }
  },
  {
    title: "审核人",
    dataIndex: "check_user",
    formType: "select",
    addDisplay: false,
    search: true,
    dict: {
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      url: "system/user/index",
      // 指定组件接收的props
      props: { label: "nickname", value: "id" },
      // 开启分页
      params: {
        page:1,
        pageSize:10000,
      },
      // 远程请求配置项
      remoteOption: {
        // 按用户名排序
        sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
        // 设置查询的字段
        select: ["id", "nickname"],
        // 设置数据过滤
        // 关联模型
        relations: [],
      },
      translation:true,
    },
  },
  {
    title: "审核时间",
    dataIndex: "check_time",
    formType: "range",
    addDisplay: false,
    search: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "textarea",
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'financial:moneyApply' } </script>